<template>
	<div class="app-container">
		<!-- 高级查询 -->
		<el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">

			<el-form-item label="仓库:">
				<el-select v-model="queryParams.warehouseCode" filterable clearable placeholder="请选择"
					@change="handleSelectedWarehouse">
					<el-option v-for="item in  options.warehouseCodes" :key="item.id" :label="item.warehouserName"
						:value="item.id">
					</el-option>
				</el-select>
			</el-form-item>

			<el-form-item label="库区:">
				<el-select v-model="queryParams.area" clearable placeholder="请选择">
					<el-option v-for="item in  options.areas" :key="item.id" :label="item.areaName" :value="item.id">
					</el-option>
				</el-select>
			</el-form-item>

			<!-- <el-form-item label="选择商品车:" prop="materialNo">
				<el-input v-model="queryParams.materialNo" class="filter-item">
					<i slot="suffix" class="el-input__icon el-icon-search" @click="openMaterialSelector" />
				</el-input>
				<warehouse-customer-selector ref="warehouseCustomerSelector" :visible.sync="materialSelectorVisible"
					@selected="handleMaterialSelected" />
			</el-form-item> -->

			<!-- VIN搜索 -->
			<el-form-item label="VIN号:" prop="vinNos" class="item-flot">
				<el-input v-model="vinNos1" placeholder="多个VIN以逗号或空格分隔" type="textarea" clearable />
			</el-form-item>

      <el-form-item label="VIN号:" prop="vinNos" class="item-flot">
      	<el-input v-model="queryParams.vinNo" placeholder="单个vin号模糊查询"  clearable />
      </el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
				<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
			</el-form-item>
			<el-form-item>
				<el-button type="warning" icon="el-icon-top" @click="handleQuery">导出</el-button>
			</el-form-item>
      <div style="float: right;">
				<el-button :disabled="!multipleSelection.length" type="info" icon="el-icon-top" @click="fromDialog('车辆外借')">车辆外借</el-button>
				<el-button :disabled="!multipleSelection.length" type="info" icon="el-icon-top" @click="fromDialog('车辆维修')">车辆维修</el-button>
				<el-button :disabled="!multipleSelection.length" type="info" icon="el-icon-top" @click="fromDialog('车辆退库')">车辆退库</el-button>
			</div>
		</el-form>

		<!-- 工具栏 -->
		<!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tbWmsMaterialInLocation:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tbWmsMaterialInLocation:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tbWmsMaterialInLocation:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tbWmsMaterialInLocation:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row> -->

    <el-dialog :title="vehiclelnLocationDataFormDialog.title" :visible.sync="vehiclelnLocationDataFormDialog.visible" :close-on-click-modal="false" :before-close="resetFormDialog" width="600px" append-to-body>
      <!-- 借车 -->
      <el-form v-if="vehiclelnLocationDataFormDialog.title=='车辆外借'" ref="newTbWmsMaterialDeliveryForm1" :model="lendCarFormData" :rules="newTbWmsMaterialDeliveryFormRules" label-width="120px ">
          <el-form-item label="借车人:" prop="">
            <el-input v-model="lendCarFormData.lendCarPerson" placeholder="请输入借车人" clearable />
          </el-form-item>
          <el-form-item label="借车单位:" prop="">
            <el-input v-model="lendCarFormData.lendCarCompany" placeholder="请输入借单位" clearable />
          </el-form-item>
          <el-form-item label="借车日期:" prop="">
            <el-date-picker v-model="lendCarFormData.lendCarDate" type="date" value-format="yyyy-MM-dd" placeholder="借车日期" clearable style="width:100%" />
          </el-form-item>
          <el-form-item label="预计还车日期:" prop="">
            <el-date-picker v-model="lendCarFormData.returnCarDate" type="date" value-format="yyyy-MM-dd" placeholder="预计还车日期" clearable style="width:100%" />
          </el-form-item>
          <el-form-item label="备注:" prop="">
            <el-input v-model="lendCarFormData.remark" type="textarea" placeholder="请输入备注" clearable  />
          </el-form-item>
          <el-form-item label="上传附件:" >
            <el-upload
              ref="upload"
              :limit="1"
              :headers="uploadData.headers"
              :action="uploadData.url"
              :data="uploadData.params"
              :disabled="uploadData.isUploading"
              :on-progress="handleFileUploadProgress"
              :on-success="handleFileSuccess"
              :on-error="handleFileError"
              :auto-upload="false"
              drag
              >
              <!-- :show-file-list="true" -->
              <!-- accept=".xlsx, .xls" -->
              <i class="el-icon-upload" />
              <div class="el-upload__text">
                将文件拖到此处，或
                <em>点击上传</em>
              </div>
              <!-- <div slot="tip" class="el-upload__tip"> -->
                <!-- <el-link type="info" style="font-size:12px" @click="handleDownloadTemplate">下载模板</el-link> -->
              <!-- </div> -->
              <!-- <div slot="tip" class="el-upload__tip" style="color:red">提示：仅允许导入“xls”或“xlsx”格式文件！</div> -->
            </el-upload>
          </el-form-item>
      </el-form>
      <!-- 维修 -->
      <el-form v-else-if="vehiclelnLocationDataFormDialog.title=='车辆维修'" ref="newTbWmsMaterialDeliveryForm1" :model="repairCarFormData" :rules="newTbWmsMaterialDeliveryFormRules" label-width="120px ">
          <el-form-item label="责任人:" prop="">
            <el-input v-model="repairCarFormData.lendCarPerson" placeholder="请输入责任人" clearable />
          </el-form-item>
          <el-form-item label="维修单位/地址:" prop="">
            <el-input v-model="repairCarFormData.repairCompany" placeholder="请输入维修单位/地址" clearable />
          </el-form-item>
          <el-form-item label="维修日期:" prop="">
            <el-date-picker v-model="repairCarFormData.lendCarDate" type="date" value-format="yyyy-MM-dd" placeholder="维修日期" clearable style="width:100%" />
          </el-form-item>
          <el-form-item label="备注:" prop="">
            <el-input v-model="repairCarFormData.remark" type="textarea" placeholder="请输入备注" clearable  />
          </el-form-item>
          <el-form-item label="上传附件:" >
            <el-upload
              ref="upload"
              :limit="1"
              :headers="uploadData.headers"
              :action="uploadData.url"
              :data="uploadData.params"
              :disabled="uploadData.isUploading"
              :on-progress="handleFileUploadProgress"
              :on-success="handleFileSuccess"
              :on-error="handleFileError"
              :auto-upload="false"
              drag
              >
              <i class="el-icon-upload" />
              <div class="el-upload__text">
                将文件拖到此处，或
                <em>点击上传</em>
              </div>
            </el-upload>
          </el-form-item>
      </el-form>
      <!-- 退库 -->
      <el-form v-else ref="newTbWmsMaterialDeliveryForm1" :model="refundCarFormData" :rules="newTbWmsMaterialDeliveryFormRules" label-width="120px ">
          <!-- <el-form-item label="责任人:" prop="">
            <el-input v-model="refundCarFormData.lendCarPerson" placeholder="请输入责任人" clearable />
          </el-form-item> -->
          <!-- <el-form-item label="退库单位/地址:" prop="">
            <el-input v-model="refundCarFormData.repairCompany" placeholder="请输入退库单位/地址" clearable />
          </el-form-item> -->
          <el-form-item label="退库日期:" prop="">
            <el-date-picker v-model="refundCarFormData.lendCarDate" type="date" value-format="yyyy-MM-dd" placeholder="维修日期" clearable style="width:100%" />
          </el-form-item>
          <el-form-item label="备注:" prop="">
            <el-input v-model="refundCarFormData.remark" type="textarea" placeholder="请输入备注" clearable  />
          </el-form-item>
          <!-- <el-form-item label="上传附件:" >
            <el-upload
              ref="upload"
              :limit="1"
              :headers="uploadData.headers"
              :action="uploadData.url"
              :data="uploadData.params"
              :disabled="uploadData.isUploading"
              :on-progress="handleFileUploadProgress"
              :on-success="handleFileSuccess"
              :on-error="handleFileError"
              :auto-upload="false"
              drag
              >
              <i class="el-icon-upload" />
              <div class="el-upload__text">
                将文件拖到此处，或
                <em>点击上传</em>
              </div>
            </el-upload>
          </el-form-item> -->
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmFormDialog">确 定</el-button>
        <el-button @click="resetFormDialog">取 消</el-button>
      </div>
    </el-dialog>

		<!-- 数据列表 -->
		<el-table v-loading="loading" :data="page.records" highlight-current-row
			@selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="序号" type="index" width="55" align="center" />
			<!-- <el-table-column label="区域编码" align="center" prop="warehouseCode" /> -->

		  <el-table-column label="整车序列号(VIN码)" align="center" prop="receivedLineList[0].vinNo" />
		  <el-table-column label="状态" align="center" prop="">
        <template slot-scope="scope">
          {{statusFn(scope.row.status)}}
        </template>
      </el-table-column>
		  <el-table-column label="品牌" align="center" prop="materialName" />
		  <el-table-column label="仓库" align="center" prop="warehouseName" />
		  <el-table-column label="库区" align="center" prop="areaName" />
		  <el-table-column label="库位" align="center" prop="locationNo" />
		  <el-table-column label="商品车编号" align="center" prop="materialNo" />
		  <!-- <el-table-column label="计划入库日期" align="center" prop="receivedLineList[0].planInBoundDate" /> -->
		  <el-table-column label="应入库日期" align="center" prop="receivedLineList[0].shouldInDate" />
		  <!-- <el-table-column label="首次入库日期" align="center" prop="receivedLineList[0].firstInBoundDate" /> -->
		  <el-table-column label="实际入库日期" align="center" prop="receivedLineList[0].receivedTime" />
		  <el-table-column label="物料描述" align="center" prop="receivedLineList[0].materialDesc" />
		  <el-table-column label="驾驶室" align="center" prop="receivedLineList[0].driverCabinDesc" />
		  <el-table-column label="变速器型号" align="center" prop="receivedLineList[0].transmission" />
		  <el-table-column label="车型代号" align="center" prop="receivedLineList[0].vehicleModel" />
		  <el-table-column label="发动机号" align="center" prop="receivedLineList[0].engineNo" />
		  <el-table-column label="发动机型号" align="center" prop="receivedLineList[0].engineModel" />
		  <el-table-column label="DMS订单号" align="center" prop="receivedLineList[0].dmsOrderNo" />
      <!-- 新增字段 -->
      <el-table-column label="厂区/物流部" align="center" prop="" />
      <el-table-column label="物流公司中心库真实停车位" align="center" prop="" />
      <el-table-column label="物流公司真实入库日期" align="center" prop="" />
      <el-table-column label="物流公司外租库仓库名称" align="center" prop="" />
      <el-table-column label="物流公司外租库真实停车位" align="center" prop="" />
      <el-table-column label="溢库短驳外租库真实日期" align="center" prop="" />

		</el-table>

		<!-- 分页 -->
		<pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize"
			@pagination="handleQuery" />

		<!-- 添加/修改对话框 -->
		<el-dialog :title="tbWmsMaterialInLocationFormDialog.title"
			:visible.sync="tbWmsMaterialInLocationFormDialog.visible" :close-on-click-modal="false" width="500px"
			append-to-body>
			<el-form ref="tbWmsMaterialInLocationForm" :model="tbWmsMaterialInLocationFormData"
				:rules="tbWmsMaterialInLocationFormRules" label-width="80px">
				<!-- <el-form-item label="" prop="siteCode">
          <el-input v-model="tbWmsMaterialInLocationFormData.siteCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="warehouseCode">
          <el-input v-model="tbWmsMaterialInLocationFormData.warehouseCode" placeholder="请输入" />
        </el-form-item> -->
				<el-form-item label="库架编号" prop="locationNo">
					<el-input v-model="tbWmsMaterialInLocationFormData.locationNo" placeholder="请输入库架编号" />
				</el-form-item>
				<el-form-item label="物品编号" prop="materialNo">
					<el-input v-model="tbWmsMaterialInLocationFormData.materialNo" placeholder="请输入物品编号" />
				</el-form-item>
				<!-- <el-form-item label="" prop="customerNo">
          <el-input v-model="tbWmsMaterialInLocationFormData.customerNo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="batchNo">
          <el-input v-model="tbWmsMaterialInLocationFormData.batchNo" placeholder="请输入" />
        </el-form-item> -->
				<el-form-item label="数量" prop="quantity">
					<el-input v-model="tbWmsMaterialInLocationFormData.quantity" placeholder="请输入数量" />
				</el-form-item>
				<!-- <el-form-item label="" prop="validityDate">
          <el-date-picker v-model="tbWmsMaterialInLocationFormData.validityDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 200px" placeholder="选择" clearable />
        </el-form-item>
        <el-form-item label="" prop="version">
          <el-input v-model="tbWmsMaterialInLocationFormData.version" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="checkNo">
          <el-input v-model="tbWmsMaterialInLocationFormData.checkNo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="lotNo">
          <el-input v-model="tbWmsMaterialInLocationFormData.lotNo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cellNo">
          <el-input v-model="tbWmsMaterialInLocationFormData.cellNo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="customerId">
          <el-input v-model="tbWmsMaterialInLocationFormData.customerId" placeholder="请输入" />
        </el-form-item> -->
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="confirmTbWmsMaterialInLocationFormDialog">确 定</el-button>
				<el-button @click="resetTbWmsMaterialInLocationFormDialog">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import TbWmsMaterialInLocationApi from '@/api/web/TbWmsMaterialInLocationApi'
	import WarehouseCustomerSelector from '@/views/pms/tWhWarehouseCustomerMaterial/WarehouseCustomerSelector'
	import WarehouseApi from '@/api/basic/WarehouseApi'
	import WarehouseAreaApi from '@/api/web/WarehouseAreaApi'
  import AuthUtils from '@/utils/AuthUtils'
	const defaultTbWmsMaterialInLocationFormData = {
		siteCode: null,
		warehouseCode: null,
		locationNo: null,
		materialNo: null,
		customerNo: null,
		batchNo: null,
		quantity: null,
		validityDate: null,
		version: null,
		checkNo: null,
		lotNo: null,
		cellNo: null,
		customerId: null,
	}
	export default {
		name: 'TbWmsMaterialInLocationList',
		components: {

			WarehouseCustomerSelector

		},
		props: {
			warehouseCode: {
				type: String,
				default: null
			}
		},
		data() {
			return {
        uploadData: {
          headers: { Authorization: 'Bearer ' + AuthUtils.getToken() }, // 上传请求头
          url: process.env.VUE_APP_BASE_API + '/system/attachment/upload', // 上传的地址
          params: {
          },
          isUploading: false, // 是否禁用上传
          updateSupport: 0 // 是否更新已经存在的数据
        },
        newTbWmsMaterialDeliveryFormRules:{},  // 校验
        // selectedCarArr: null,  // 选中的车辆数据
        lendCarFormData: {
          ids: null,  // 选中的车辆ID
          type: 'lend',  // 状态 / 外借
          lendCarPerson: null,  // 借车人
          lendCarCompany: null,  // 借车单位
          lendCarDate: null,  // 借车日期
          returnCarDate: null,  // 预计还车日期
          remark: null,  // 备注
          url: null,  // 附件
        },
        repairCarFormData: {
          ids: null,  // 选中的车辆ID
          type: 'repair',  // 状态 / 维修
          lendCarPerson: null,  // 责任人
          repairCompany: null,  // 维修单位
          lendCarDate: null,  // 维修日期
          remark: null,  // 备注
          url: null,  // 附件
        },
        refundCarFormData: {
          ids: null,  // 选中的车辆ID
          type: 'refund',  // 状态 / 退库
          // lendCarPerson: null,  // 责任人
          // refundCompany: null,  // 退库单位
          lendCarDate: null,  // 退库日期
          remark: null,  // 备注
          // url: null,  // 附件
        },
        vehiclelnLocationDataFormDialog: {
          title: '',
          visible: false,
        },
				options: {
					warehouseCodes: [],
					areas: [],
					sysYnTypeOptions: this.$constant.sysYnTypeOptions
				},
        vinNos1: null,
				queryParams: {
          // status:"inposition",  // 状态过滤--------------------------------------------正常
					vinNos: null, // VIN查询
					siteCode: null,
					warehouseCode: null,
					locationNo: null,
					materialNo: null,
					materialName: null,
					customerNo: null,
					batchNo: null,
					quantity: null,
					validityDate: null,
					version: null,
					checkNo: null,
					lotNo: null,
					cellNo: null,
					customerId: null,
          vinNo: null,
					isValid: this.$constant.Y
				},
				page: {
					current: 1,
					pageSize: 10,
					total: 0,
					records: []
				},
				tbWmsMaterialInLocationFormDialog: {
					title: '',
					visible: false
				},
				tbWmsMaterialInLocationFormData: Object.assign({}, defaultTbWmsMaterialInLocationFormData),
				tbWmsMaterialInLocationFormRules: {
					siteCode: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					warehouseCode: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					locationNo: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					materialNo: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					customerNo: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					quantity: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					version: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
				},
				loading: true,
				searchVisible: true,
				multipleSelection: [],  ///////////////// 多选框数据
				materialSelectorVisible: false,
				isSingle: true,
				isMultiple: true
			}
		},
		created() {
			this.handleQuery()
			this.loadOptions()
		},
		methods: {
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        // console.log(event);
        // console.log(file);
        // console.log(fileList);
        console.log(1);
        this.uploadData.isUploading = true
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        console.log(2);
        console.log(response.data[0].fileUrl);
        if(this.vehiclelnLocationDataFormDialog.title=='车辆外借'){
          this.lendCarFormData.url = response.data[0].fileUrl
          console.log(this.lendCarFormData);
          TbWmsMaterialInLocationApi.InventoryLending(this.lendCarFormData).then(
            response => {
              this.$message.success('外借成功')
              this.resetFormDialog()
              this.handleQuery()
            }
          )
        }else if(this.vehiclelnLocationDataFormDialog.title=='车辆维修'){
          this.repairCarFormData.url = response.data[0].fileUrl
          console.log(this.repairCarFormData);
          TbWmsMaterialInLocationApi.InventoryLending(this.repairCarFormData).then(
            response => {
              this.$message.success('成功')
              this.resetFormDialog()
              this.handleQuery()
            }
          )
        }
        // console.log(response);
        // console.log(file);
        // console.log(fileList);
        this.uploadData.isUploading = false
        this.$refs.upload.clearFiles()
        // this.$alert(response.data ? response.data : response.msg, '导入结果', { dangerouslyUseHTMLString: true })
        this.handleQuery()
      },
      // 文件上传成功处理
      // handleFileSuccess(response, file, fileList) {
      //   this.uploadData.isUploading = false
      //   if (response.code === 200) {
      //     this.attach.applyAttachmentUrl = response.data[0].fileUrl
      //   } else {
      //     fileList.pop()
      //     this.$message.error(response.msg)
      //   }
      // },
      // 文件上传失败理
      handleFileError(){
        this.$message.success('附件上传失败成功')
        this.uploadData.isUploading = false
      },


			loadOptions() {
				let that = this
				WarehouseApi.list().then(response => {
					that.options.warehouseCodes = response.data                 //    ------------- 仓库数据
				})
			},
			handleAdd() {
				this.openTbWmsMaterialInLocationFormDialog()
			},
			handleRemove(row) {
				const ids = row.id || this.multipleSelection.map(item => item.id)
				this.$confirm('是否确认删除数据?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(function() {
					return TbWmsMaterialInLocationApi.remove(ids)
				}).then(() => {
					this.handleQuery()
					this.$message.success('删除成功')
				})
			},
			handleMaterialSelected(obj) {
				this.queryParams.materialNo = obj.id
			},
			handleEdit(row) {
				const id = row.id || this.multipleSelection.map(item => item.id)[0]
				this.openTbWmsMaterialInLocationFormDialog(id)
			},
			handleQuery() {
				this.loading = true
        //this.queryParams.warehouseCode = this.warehouseCode
        ///////////////////////////////////////////////////////////this.queryParams.vinNos是多项VIN查询的数组
        if(this.vinNos1 && this.queryParams.vinNos == null ){
          this.queryParams.vinNos = this.vinNos1.replace(/[；,，;\s\r\n]+/g, ",").split(",");
        } else {
          this.queryParams.vinNos = null
        }
        console.log(this.queryParams.vinNos);  // VIN数组

				TbWmsMaterialInLocationApi.page(this.queryParams, this.page).then(response => {
          console.log(response.data.records);
          console.log(response);
					this.page.records = response.data.records
					this.page.total = response.data.total
					this.loading = false
          this.queryParams.vinNos = null
				}, () => {
					this.loading = false
				})
			},

			handleSelectedWarehouse(v) {
        console.log(v);
				let that = this
				if (this.queryParams.warehouseCode != null) {
					WarehouseAreaApi.list({
						warehouseId: v
					}).then(response => {
						that.options.areas = response.data           //       ----------------库区数据
					})
				}

			},
			handleExport() {
				this.$confirm('是否确认导出数据?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(function() {
					return TbWmsMaterialInLocationApi.exportData(this.queryParams)
				}).then(response => {
					this.$common.download(response.msg)
				})
			},
			openMaterialSelector() {
				this.$refs.warehouseCustomerSelector.loadData()
				this.materialSelectorVisible = true
			},
			openTbWmsMaterialInLocationFormDialog(id) {
				this.resetTbWmsMaterialInLocationFormDialog()
				this.tbWmsMaterialInLocationFormDialog.visible = true
				if (id) {
					this.tbWmsMaterialInLocationFormDialog.title = '货区货物清单-修改'
					TbWmsMaterialInLocationApi.get(id).then(response => {
						this.tbWmsMaterialInLocationFormData = {
							...this.tbWmsMaterialInLocationFormData,
							...response.data
						}
					})
				} else {
					this.tbWmsMaterialInLocationFormDialog.title = '货区货物清单-添加'
				}
			},
			confirmTbWmsMaterialInLocationFormDialog() {
				this.$refs['tbWmsMaterialInLocationForm'].validate(valid => {
					if (valid) {
						if (this.tbWmsMaterialInLocationFormData.id) {
							TbWmsMaterialInLocationApi.edit(this.tbWmsMaterialInLocationFormData).then(
								response => {
									this.$message.success('修改成功')
									this.tbWmsMaterialInLocationFormDialog.visible = false
									this.handleQuery()
								})
						} else {
							TbWmsMaterialInLocationApi.add(this.tbWmsMaterialInLocationFormData).then(response => {
								this.$message.success('添加成功')
								this.tbWmsMaterialInLocationFormDialog.visible = false
								this.handleQuery()
							})
						}
					}
				})
			},
			resetTbWmsMaterialInLocationFormDialog() {
				this.tbWmsMaterialInLocationFormDialog = {
					title: '',
					visible: false
				}
				this.tbWmsMaterialInLocationFormData = Object.assign({}, defaultTbWmsMaterialInLocationFormData)
				this.resetForm('tbWmsMaterialInLocationForm')
			},
			handleSelectionChange(selection) {  // 选择框事件
        console.log(selection);
				this.multipleSelection = selection
				this.isSingle = selection.length !== 1
				this.isMultiple = !selection.length
			},
      fromDialog(val) {  // 点击车辆外借 / 车点击辆维修 / 点击车辆退库
        this.vehiclelnLocationDataFormDialog={
          title: val,
          visible: true
        }
        if(val=='车辆外借'){
          this.lendCarFormData.ids = this.multipleSelection.map(item => item.id)
        }else if(val=='车辆维修'){
          this.repairCarFormData.ids = this.multipleSelection.map(item => item.id)
        }else if(val=='车辆退库'){
          this.refundCarFormData.ids = this.multipleSelection.map(item => item.id)
        }
        console.log('外借',this.lendCarFormData.ids);
        console.log('维修',this.repairCarFormData.ids);
        console.log('退库',this.refundCarFormData.ids);
			},
      resetFormDialog(){   // ----------//-----取消
        this.vehiclelnLocationDataFormDialog={
          title: '',
          visible: false
        }
        this.lendCarFormData= {
          ids: null,  // 选中的车辆ID
          type: 'lend',  // 状态
          lendCarPerson: null,  // 借车人
          lendCarCompany: null,  // 借车单位
          lendCarDate: null,  // 借车日期
          returnCarDate: null,  // 预计还车日期
          remark: null,  // 备注
          url: null,  // 附件
        }
        this.repairCarFormData= {
          ids: null,  // 选中的车辆ID
          type: 'repair',  // 状态
          lendCarPerson: null,  // 责任人
          repairCompany: null,  // 维修单位
          lendCarDate: null,  // 维修日期
          remark: null,  // 备注
          url: null,  // 附件
        }
        this.refundCarFormData= {
          ids: null,  // 选中的车辆ID
          type: 'refund',  // 状态
          // lendCarPerson: null,  // 责任人
          // refundCompany: null,  // 退库单位
          lendCarDate: null,  // 退库日期
          remark: null,  // 备注
          // url: null,  // 附件
        }
        this.attach = {
          id: null,
          applyAttachmentUrl: null
        }
      },
      confirmFormDialog(){   // ------//------确认
        console.log('借车数据',this.lendCarFormData);
        console.log('维修数据',this.repairCarFormData);
        console.log('退库数据',this.refundCarFormData);
        if(this.vehiclelnLocationDataFormDialog.title=='车辆退库'){
          TbWmsMaterialInLocationApi.InventoryLending(this.refundCarFormData).then(
            response => {
              this.$message.success('退库成功')
              this.resetFormDialog()
              this.handleQuery()
            }
          )
        }else{
          this.$refs.upload.submit()    //  -------------------------------------------------上传
          if(!this.lendCarFormData.url && !this.repairCarFormData.url){
            this.$message.success('请您上传附件！')
          }
        }


        // await this.handleFileSuccess()
        // console.log(this.lendCarFormData);
        // if(this.vehiclelnLocationDataFormDialog.title=='车辆外借'){
        //   TbWmsMaterialInLocationApi.InventoryLending(this.lendCarFormData).then(
        //     response => {
        //       console.log('0000000000000000000');
        //       this.$message.success('外借成功')
        //       this.resetFormDialog()
        //       this.handleQuery()
        //     }
        //   )
        // }else if(this.vehiclelnLocationDataFormDialog.title=='车辆维修'){
        //   TbWmsMaterialInLocationApi.InventoryLending(this.repairCarFormData).then(
        //     response => {
        //       this.$message.success('成功')
        //       this.resetFormDialog()
        //       this.handleQuery()
        //     }
        //   )
        // }
      },
      statusFn(val){
        switch(val){
            case 'lend':
                return '外借';
                break;
            case 'repair':
                return '维修';
                break;
            case 'refund':
                return '退库';
                break;
            // case 'inposition':
            //   return '正常';
            //   break;
            // default:
            //     return val;
            default:
                return '正常';
        }
      },



			resetQuery() {
				this.page.current = 1
				this.resetForm('queryForm')
				this.handleQuery()
			}
		}
	}
</script>
